//
//  JuInfo.swift
//  YeKa
//
//  Created by Gina on 15/10/17.
//  Copyright © 2015年 Gina. All rights reserved.
//

import UIKit

class JuInfo: NSObject {

    var event: Int = 0
    var now: Int = 0
    var type: Int = 0
    
    var theme:String?
    var name:String?
    var man:Int = 0
    var imageUrl:String?
    var price:String?
    var timeAll:String?
    var detailTime:String?
    
    
    
    init(dict: [String: AnyObject]) {
        super.init()
        setValuesForKeysWithDictionary(dict)
    }
    
    override func setValue(value: AnyObject?, forUndefinedKey key: String) {}
    
    class func loadJuList(finished: (dataList: [JuInfo]?, error:NSError?) -> ()){
        let urlString = "parties/recParty?size=3"
        NetworkTools.sharedNetworkTools.request(YeKaNetworkMethod.GET, urlString: urlString, params: nil) { (result, error) -> () in
            
            
            if let juTypeArray = result?["data"] as? [[String: AnyObject]] {
                var juinfolist = [JuInfo]()
                var i = 0
                for dict in juTypeArray {
                    let j = JuInfo(dict: dict)
                    juinfolist.append(j)
                    
                    var temp = [[String: AnyObject]]()
                    if j.type == 1 {
                        temp = result?["data"]?[i]["partyVoList"] as! [[String: AnyObject]]
                    }else{
                        temp = result?["data"]?[i]["gatherList"] as! [[String: AnyObject]]
                    }
                    
                    for dict1 in temp {
                        if j.type == 1 {
                            
                            let tt: JuInfo = JuInfo(dict: dict1["party"] as! [String: AnyObject])
                            tt.type = 0
                            tt.imageUrl = dict1["party"]!["picture"] as? String
                            tt.name = "玩聚北京"
                            tt.theme = dict1["party"]!["name"] as? String
                            
                            let jiagelist:[[String: AnyObject]] = dict1["party"]!["tickets"] as! [[String: AnyObject]]
                            let pp = jiagelist[0]["price"] as! Int
                            
                            tt.price = String(pp)

                            juinfolist.append(tt)
                            
                            
                        }else{
                            juinfolist.append(JuInfo(dict: dict1))
                        }
                        
                    }
                    i++
                }
                
                
                finished(dataList: juinfolist, error: nil)

            }else{
                finished(dataList: nil, error: nil)
            }
            
            
        }
        
        
    }
    
}
